﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace ArgusControls
{
	public class DoubleClickLayer : Layer
	{
		DispatcherTimer timer;

		public DoubleClickLayer()
			: base()
		{
			this.timer = new DispatcherTimer();
			this.timer.Interval = new TimeSpan(0, 0, 0, 0, 300);
			this.timer.Tick += timer_Tick;
		}

		void timer_Tick(object sender, EventArgs e)
		{
			this.timer.Stop();
		}

		public event MouseButtonEventHandler MouseDoubleLeftClick;

		protected virtual void OnMouseDoubleLeftClick(MouseButtonEventArgs e)
		{
			if (this.MouseDoubleLeftClick != null)
				this.MouseDoubleLeftClick(this, e);
		}

		protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
		{
			if (this.timer.IsEnabled == false)
			{
				this.timer.Start();
			}
			else
			{
				this.OnMouseDoubleLeftClick(e);
				this.timer.Stop();
			}
			base.OnMouseLeftButtonUp(e);
			e.Handled = false;
		}
	}
}
